<?php
$pagename= "Data Entry- Books";
require_once "auth.php";
include "connect.php";
include "header.php";
//this clears all veribles to prevent errors later




if (isset($_GET['status'])) {
echo "Form Processing...<br>Done!";
if ($_GET['status'] == "added") {
echo "<h3><font color='green'>SUCCESS! Write this Down: <b>Barcode: <i>";
echo $_GET["barcode"];
echo "</i> Book Name: <i>";
echo $_GET["name"];
echo "</i> Author (Last,First) <i>";
echo $_GET["author_last"];
echo " , ";
echo $_GET['author_first'];
echo "</i> Call Number: <i>";
echo $_GET['callnum'];
echo "</i></font></h3>";
}
if ($_GET['status'] == "notfilled") {
echo "<h3><font color='red'>Please Try Again- ALL FEILDS REQUIRED</font></h3>";
}
}
	

// Access key (obtain one by creating a free account at: https://isbndb.com/account/create.html, and enter it here. It will not work without the access key.)
$accessKey = "HT9F2ZLP";

// Get Post variables

$query = $_POST['query'];




	
	// Urls
	$url_details = "http://isbndb.com/api/books.xml?access_key=$accessKey&results=details&index1=isbn&value1=$query";
	$url_texts = "http://isbndb.com/api/books.xml?access_key=$accessKey&results=texts&index1=isbn&value1=$query";
	$url_prices = "http://isbndb.com/api/books.xml?access_key=$accessKey&results=prices&index1=isbn&value1=$query";
	$url_subjects = "http://isbndb.com/api/books.xml?access_key=$accessKey&results=subjects&index1=isbn&value1=$query";
	
	// API lookup ISBN value at isbndb.com
	$xml_prices = @simplexml_load_file($url_prices) or die ("no file loaded") ;
	$xml_details = @simplexml_load_file($url_details) or die ("no file loaded") ;
	
	// Parse Data
	$isbn = 		$xml_prices->BookList[0]->BookData[0]['isbn'] ;
	$title = 		$xml_prices->BookList[0]->BookData[0]->Title ;
	$titleLong =	$xml_prices->BookList[0]->BookData[0]->TitleLong ;
	$authors =		$xml_prices->BookList[0]->BookData[0]->AuthorsText ;
	$publisher =	$xml_prices->BookList[0]->BookData[0]->PublisherText ;
	$dewey =		$xml_details->BookList[0]->BookData[0]->Details[0]['dewey_decimal_normalized'] ;
	$lcc =			$xml_details->BookList[0]->BookData[0]->Details[0]['lcc_number'] ;

	// Calculate average price (new)
	


?>
		
		
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>

<script>
var $input = $('input:text'),
    $register = $('#register');

$register.attr('disabled', true);
$input.keyup(function() {
    var trigger = false;
    $input.each(function() {
        if (!$(this).val()) {
            trigger = true;
        }
    });
    trigger ? $register.attr('disabled', true) : $register.removeAttr('disabled');
});
</script>
</head>
<body>
<h4>Try Again?</h4>
<form method="post" action="#">
ISBN: <input type="text" id="name"size="11" name="query"/><br>
<input type="submit" value="Retrive Info!"/>
</form>
<h3>VERIFY ALL INFOMATION BEFORE YOU SUBMIT</h3>
<form method="get" action="bookman/addbook_go.php" >

Book Name <input type="text" id="name"size="80" name="bookname" value="<?echo $title?>"/><br>

AUTHOR INFO: <?echo $authors?><br>
Author Last Name <input type="text" id="auth1" size="80" name="authlast"/><br>
Author First Name <input type="text" id="auth2" size="80" name="authfirst"/><br>
Publisher <input type="text" id="pub"size="80" name="publisher" value="<?echo $publisher?>"/><br>
ISBN-10 (BOOKS ONLY NO DASHES!) <input type="text" id="isbn" size="30" name="isbn" value="<?echo $isbn?>"/><br>
<h3>Double Check This!!!!!!</h3><br>
Dewey Decimal / Call Number  <input type="text" id="gen" size="80" name="call"value="<?echo $dewey?>"/><br>
Fiction, Non-Fiction or N/A?
<select name="fiction">
<option value="true">Fiction</option>
<option value="false">Non-Fiction</option>
</select><br>
Media Type
<select name="media">
<option value="book">Book</option>
</select><br>
In House Use Only: Yes <input type="radio" name="inhouse" value="true" /> No <input type="radio" name="inhouse" value="false" checked="checked" />  <br>

 <input type='text' value='<?php echo time(); ?>' name='time' hidden/>
<input type="submit" id="register" value="Register" />
</form>


</body>
</html>
</html>